package com.yt.system.dao;

import com.yt.system.domain.GroupTable;
import com.yt.system.domain.ObjectiveKeyresults;
import com.yt.system.domain.User;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GroupMapper {
    int deleteByPrimaryKey(Integer gid);

    int insert(GroupTable record);

    int insertSelective(GroupTable record);

    GroupTable selectByPrimaryKey(Integer gid);

    int updateByPrimaryKeySelective(GroupTable record);

    int updateByPrimaryKey(GroupTable record);

    List<GroupTable> getGroups();

    //1.查所有组名
//    @Select("SELECT g.gid, g.gname FROM`group` g;")
    @Select("SELECT * FROM grouptable gt where gt.gstatus=0")
    List<GroupTable> selectGName();

    //2.根据小组id查询uid，uname
//    @Select("select user.uid,user.uname from user left join group_message on user.uid=group_message.uid where group_message.gid=#{gid};")
    @Select("select * from user left join group_message gm on user.uid=gm.uid where gm.gid=#{gid} and gm.status=0;")
    List<User> selectGroup(int gid);

    //4.根据小组id查询okr
//    @Select("SELECT g.gid,g.gname,o.oid, o.ocontent, k.krcontent, k.krid, k.oid FROM objective o LEFT JOIN keyresults k ON o.oid = k.oid LEFT JOIN `grouptable` g ON o.oid = g.oid WHERE g.gid=#{gid};")
    @Select("SELECT * FROM objective o  LEFT JOIN keyresults k ON o.oid = k.oid  LEFT JOIN `okr_group` g ON o.oid = g.oid  LEFT JOIN  grouptable gt ON g.gid=gt.gid  WHERE gt.gstatus=0 and g.gid= #{gid}")
    List<ObjectiveKeyresults> selectOkr(int gid);

    //5.根据小组id查成员okr
    @Select("SELECT * FROM objective o LEFT JOIN keyresults k ON o.oid = k.oid LEFT JOIN account a  ON o.oid=a.oid LEFT JOIN user u  ON a.aid=u.uid WHERE u.uid in(SELECT u.uid FROM user u LEFT JOIN group_message gm ON u.uid=gm.uid where gm.status=0 and gm.gid=#{gid})")
    List<ObjectiveKeyresults> selectOkrBygid(int gid);
}